package com.csnf.servlet;

import com.csnf.dao.UserDao2;
import com.csnf.entity.User;
import com.csnf.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/user")
public class UserServlet2 extends HttpServlet {
    UserService userService=new UserService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String uname = req.getParameter("uName");
        String passWord = req.getParameter("passWord");
        String roleId = req.getParameter("roleId");
        System.out.println(uname+passWord+roleId);
        List<User> uList=userService.getUser(uname);
        System.out.println(uList);
        if (uList.size()>0){
            if (uList.get(0).getPassWord().equals(passWord)&& uList.get(0).getRoleId().equals(roleId)){
                req.getRequestDispatcher("singer?type=all").forward(req,resp);
            }else {
                req.setAttribute("msg","1");
                req.getRequestDispatcher("role").forward(req,resp);
            }
            }else {
            req.setAttribute("msg","0");
            req.getRequestDispatcher("role").forward(req,resp);
        }
    }
}
